$(document).ready(function() { 
	var getUrlParam = function (param) {
		var url = document.location.pathname;
		var params = url.split('/');
		return params[params.indexOf(param)+1];
	}

	var initTree = function() {
		var bookId = getUrlParam('id');	
		$("#tree").treeview({
			url: "/books/ajax/tree",			
			ajax: {
				data: {
					book_id: bookId
				},
				type: "post"
			}
		})                         
	}	

	$('li[parent="true"]').live('click', function() {		
		$(this).removeAttr("parent");
		
	})

	$('li[parent="false"]').live('click', function() {
		$(this).removeAttr("parent");
		console.log("false");
	})

	initTree();
});